import cv2

# 读取图像并转换为灰度
image = cv2.imread('example.jpg', cv2.IMREAD_GRAYSCALE)

# 应用二值化阈值处理
_, binary_image = cv2.threshold(image, 128, 255, cv2.THRESH_BINARY)

# 保存二值图像
cv2.imwrite('binary_image.jpg', binary_image)